home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / CABINETS / MSDAO350.CAB / icontrols / DataNavigator / DataNavigator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-01-08  |  6.3 KB  |  230 lines

  1. package icontrols.DataNavigator;
  2.  
  3. import com.ms.ado.DataSource;
  4. import com.ms.ado.Recordset;
  5. import com.ms.ado.adodb._Recordset;
  6. import com.ms.wd.app.Message;
  7. import com.ms.wd.core.Component;
  8. import com.ms.wd.core.Event;
  9. import com.ms.wd.core.EventHandler;
  10. import com.ms.wd.ui.Bitmap;
  11. import com.ms.wd.ui.Brush;
  12. import com.ms.wd.ui.Color;
  13. import com.ms.wd.ui.Control;
  14. import com.ms.wd.ui.Graphics;
  15. import com.ms.wd.ui.PaintEvent;
  16. import com.ms.wd.ui.Pen;
  17. import com.ms.wd.ui.Rectangle;
  18. import com.ms.wd.win32.Windows;
  19. import icontrols.HotButton;
  20.  
  21. public class DataNavigator extends Control {
  22.    private String m_dataMember = null;
  23.    private DataSource m_dataSource = null;
  24.    private Recordset m_recordset = null;
  25.    private Brush m_backgroundBrush = null;
  26.    private Brush m_textBackgroundBrush = null;
  27.    private HotButton m_first = null;
  28.    private HotButton m_previous = null;
  29.    private HotButton m_next = null;
  30.    private HotButton m_last = null;
  31.    private static final int BUTTON_WIDTH = 20;
  32.  
  33.    public void onPrevious(Object sender, Event e) {
  34.       if (this.m_recordset != null) {
  35.          try {
  36.             this.m_recordset.movePrevious();
  37.          } catch (Exception var4) {
  38.          }
  39.       }
  40.  
  41.    }
  42.  
  43.    public final DataSource getDataSource() {
  44.       return this.m_dataSource;
  45.    }
  46.  
  47.    public void onLast(Object sender, Event e) {
  48.       if (this.m_recordset != null) {
  49.          try {
  50.             this.m_recordset.moveLast();
  51.          } catch (Exception var4) {
  52.          }
  53.       }
  54.  
  55.    }
  56.  
  57.    public void setDataSource(DataSource dataSource) {
  58.       this.releaseRowset();
  59.       this.m_dataSource = dataSource;
  60.       this.acquireRowset();
  61.    }
  62.  
  63.    protected void propertyChanged(int property) {
  64.       super.propertyChanged(property);
  65.       if (property == 5) {
  66.          ((Control)this).invalidate();
  67.       }
  68.  
  69.    }
  70.  
  71.    protected void setButtonEnabled(boolean enabled) {
  72.       this.m_first.setEnabled(enabled);
  73.       this.m_previous.setEnabled(enabled);
  74.       this.m_next.setEnabled(enabled);
  75.       this.m_last.setEnabled(enabled);
  76.    }
  77.  
  78.    public DataNavigator() {
  79.       this.m_first = new HotButton();
  80.       this.m_previous = new HotButton();
  81.       this.m_next = new HotButton();
  82.       this.m_last = new HotButton();
  83.       this.m_first.addOnClick(new EventHandler(this, "onFirst"));
  84.       this.m_previous.addOnClick(new EventHandler(this, "onPrevious"));
  85.       this.m_next.addOnClick(new EventHandler(this, "onNext"));
  86.       this.m_last.addOnClick(new EventHandler(this, "onLast"));
  87.       this.m_first.setImage((new Bitmap(((Component)this).getResource("First.bmp"))).getTransparentBitmap(true));
  88.       this.m_next.setImage((new Bitmap(((Component)this).getResource("Next.bmp"))).getTransparentBitmap(true));
  89.       this.m_previous.setImage((new Bitmap(((Component)this).getResource("Previous.bmp"))).getTransparentBitmap(true));
  90.       this.m_last.setImage((new Bitmap(((Component)this).getResource("Last.bmp"))).getTransparentBitmap(true));
  91.       ((Control)this).add(this.m_first);
  92.       ((Control)this).add(this.m_previous);
  93.       ((Control)this).add(this.m_next);
  94.       ((Control)this).add(this.m_last);
  95.       ((Control)this).setBounds(0, 0, 141, 25);
  96.       this.setButtonEnabled(false);
  97.    }
  98.  
  99.    private final void acquireRowset() {
  100.       if (this.m_dataSource != null) {
  101.          Object member = this.m_dataSource.getDataMember(this.m_dataMember, _Recordset.iid);
  102.          if (member != null) {
  103.             Recordset source = null;
  104.             _Recordset rs = null;
  105.  
  106.             try {
  107.                rs = (_Recordset)member;
  108.             } catch (Exception var6) {
  109.             }
  110.  
  111.             if (rs == null) {
  112.                try {
  113.                   source = (Recordset)member;
  114.                } catch (Exception var5) {
  115.                }
  116.             } else {
  117.                source = new Recordset(rs);
  118.             }
  119.  
  120.             if (source != null) {
  121.                this.m_recordset = source;
  122.                this.setButtonEnabled(true);
  123.             }
  124.          }
  125.       }
  126.  
  127.    }
  128.  
  129.    private final void releaseRowset() {
  130.       if (this.m_recordset != null) {
  131.          this.m_recordset = null;
  132.          this.setButtonEnabled(false);
  133.          ((Control)this).invalidate();
  134.       }
  135.  
  136.    }
  137.  
  138.    public final String getDataMember() {
  139.       return this.m_dataMember;
  140.    }
  141.  
  142.    public void setDataMember(String dataMember) {
  143.       boolean changed = false;
  144.       if (this.m_dataMember != null) {
  145.          if (!this.m_dataMember.equals(dataMember)) {
  146.             changed = true;
  147.          }
  148.       } else if (dataMember != null) {
  149.          changed = true;
  150.       }
  151.  
  152.       if (changed) {
  153.          this.releaseRowset();
  154.          this.m_dataMember = dataMember;
  155.          this.acquireRowset();
  156.       }
  157.  
  158.    }
  159.  
  160.    protected void wndProc(Message msg) {
  161.       switch (msg.msg) {
  162.          default:
  163.             super.wndProc(msg);
  164.          case 20:
  165.       }
  166.    }
  167.  
  168.    public void onFirst(Object sender, Event e) {
  169.       if (this.m_recordset != null) {
  170.          try {
  171.             this.m_recordset.moveFirst();
  172.          } catch (Exception var4) {
  173.          }
  174.       }
  175.  
  176.    }
  177.  
  178.    protected void onResize(Event e) {
  179.       Rectangle bounds = ((Control)this).getClientRect();
  180.       this.m_first.setBounds(new Rectangle(2, 2, 20, bounds.height - 4));
  181.       this.m_previous.setBounds(new Rectangle(22, 2, 20, bounds.height - 4));
  182.       this.m_next.setBounds(new Rectangle(bounds.width - 20 - 2 - 20, 2, 20, bounds.height - 4));
  183.       this.m_last.setBounds(new Rectangle(bounds.width - 20 - 2, 2, 20, bounds.height - 4));
  184.       ((Control)this).invalidate();
  185.       super.onResize(e);
  186.    }
  187.  
  188.    protected void onPaint(PaintEvent pe) {
  189.       Graphics g = pe.graphics;
  190.       Rectangle bounds = ((Control)this).getClientRect();
  191.       if (this.m_backgroundBrush == null) {
  192.          this.m_backgroundBrush = new Brush(Color.CONTROL);
  193.       }
  194.  
  195.       if (this.m_textBackgroundBrush == null) {
  196.          this.m_textBackgroundBrush = new Brush(Color.WINDOW);
  197.       }
  198.  
  199.       Rectangle textBounds = new Rectangle(bounds);
  200.       textBounds.y += 2;
  201.       textBounds.height -= 4;
  202.       textBounds.x += 42;
  203.       textBounds.width -= 84;
  204.       g.setBrush(this.m_textBackgroundBrush);
  205.       g.setPen((Pen)null);
  206.       g.drawRect(textBounds);
  207.       String text = ((Control)this).getText();
  208.       if (text != null) {
  209.          g.setTextColor(Color.WINDOWTEXT);
  210.          g.setBackColor(Color.WINDOW);
  211.          textBounds.x += 2;
  212.          textBounds.width -= 4;
  213.          g.drawString(text, textBounds, 36);
  214.       }
  215.  
  216.       Windows.DrawEdge(g.getHandle(), bounds.toRECT(), 10, 15);
  217.       super.onPaint(pe);
  218.    }
  219.  
  220.    public void onNext(Object sender, Event e) {
  221.       if (this.m_recordset != null) {
  222.          try {
  223.             this.m_recordset.moveNext();
  224.          } catch (Exception var4) {
  225.          }
  226.       }
  227.  
  228.    }
  229. }
  230.